package main

import (
	"encoding/json"
	"fmt"
)

type User struct {
	Username string `json:"username"`
	Nickname string `json:"nickname"`
	Age      int    `json:"age"`
	Birthday string
	Sex      string
	Email    string
	Phone    string
}

func testStruct() (ret string, err error) {
	user1 := &User{
		Username: "user1",
		Nickname: "simon",
		Age:      30,
		Birthday: "2013-05-03",
		Sex:      "famale",
		Email:    "simon@aliyun.com",
		Phone:    "110",
	}

	data, err := json.Marshal(user1)
	if err != nil {
		fmt.Println("json.marshal failed,err:", err)
		return
	}
	ret = string(data)
	return
}

func test() {
	data, err := testStruct()
	if err != nil {
		fmt.Println("test struct,err:", err)
		return
	}

	var user1 User
	err = json.Unmarshal([]byte(data), &user1)
	if err != nil {
		fmt.Println("json.unmarshal failed,err:", err)
		return
	}
	fmt.Println(user1)
}

func main() {
	test()
}
